package com.fly.container.context;

import com.fly.container.mapper.BlogMapper;
import com.fly.container.model.Blog;
import com.fly.container.service.DepartmentService;
import com.fly.container.service.RetryService;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.rmi.registry.Registry;
import java.util.logging.LogManager;

/**
 * @author Mr.Fu
 * @date 2024/10/6 上午11:15
 */
public class MyApplicationContext {

    public static void main(String[] args) {
//        new ClassPathXmlApplicationContext()
        // 构造函数可以执行类名称，包名称
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext("com.fly.container.service");

        // 获取一个bean
        RetryService retryService = context.getBean(RetryService.class);
        retryService.check("test check name.");

        // 手动注册BeanDefinition
//        DefaultListableBeanFactory defaultListableBeanFactory = context.getDefaultListableBeanFactory();
//        BeanDefinition logMapperBeanDefinition = new RootBeanDefinition(BlogMapper.class);
//        defaultListableBeanFactory.registerBeanDefinition("blogMapper", logMapperBeanDefinition);
    }
}
